<?php
ini_set("error_reporting","E_ALL & ~E_NOTICE");
header('Content-type: application/json');

$jsoncallback = htmlspecialchars($_REQUEST ['jsoncallback']);//获取回调函数名

$servername = "localhost";
$username = "username";//需要修改为你的 数据
$password = "password";
$dbname = "dbname";

$con = new mysqli($servername, $username, $password, $dbname);
if (mysqli_connect_errno()){// 检测连接-失败回传钉钉信息
    mysqli_close($con);//关闭数据库
    $data['status']="NO";
    $data['message']="链接数据库失败，请稍候刷新重试！";
    echo $jsoncallback . "(" . json_encode($data) . ")";//输出jsonp格式的数据
}else{//读取记录数据
    $sql = "SELECT * FROM `url`";
    $result = $con->query($sql);
    if ($result->num_rows > 0) {$i=0;
        while($row = $result->fetch_assoc()) {
            if ($row["state"] == "显示") {
                $data["url"][$i]["title"] = $row["title"];
                $data["url"][$i]["url"] = $row["url"];
                $data["url"][$i]["logo"] = "./icon/".$row["title"].".png";
                $data["url"][$i]["descriptions"] = $row["description"];
                $data["url"][$i]["keywords"] = $row["keywords"];
                $data["url"][$i]["type"] = $row["type"];
                $i++;
            }
        }
        echo $jsoncallback . "(" . json_encode($data) . ")";//输出jsonp格式的数据
    } else {
        $data['status']="NO";
        $data['message']="数据表中未查询到任何数据！";
        echo $jsoncallback . "(" . json_encode($data) . ")";//输出jsonp格式的数据
    }
    $con->close();//关闭数据库
}
?>